<template>
  <div class="reportFormPage">
    <div id="domid" class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">混凝土坍落度及扩展度经时损失试验检测记录</div>
        <div class="codeText">BGLQ05002F</div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td align="center" width="15%" height="25">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验日期</span>
              </td>
               <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>

              <td align="center" style="width: 15%">
                <span style="width: 90px; display: inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjwd }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjsd }}</span
                >%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.wend" class="height100" style="width: 15%" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.xiangdsd" class="height100" style="width: 15%" />%RH
              </td>
            </tr>
            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="580px" class="middle-table">
          <tbody>
            <tr>
              <td height="30" colspan="2" width="15%">混凝土种类</td>
              <td colspan="3">
                <el-input type="text" v-model="form.hunntzl" @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'" />
              </td>
              <td align="center" height="30" colspan="2">搅拌方式</td>
              <td colspan="4">
                <!-- <el-input type="text" v-model="form.jiaobfs" @keydown.native="handleKeyDown($event, 0, 1)" :ref="'0_1'" /> -->
                <el-select clearable v-model="form.jiaobfs"  class="hide-icon width100 height100" placeholder>
                  <el-option  label="强制式" value="强制式"></el-option>
                  <el-option  label="机械拌制" value="机械拌制"></el-option>
                  <el-option  label="人工拌制" value="人工拌制"></el-option>
                </el-select>
              </td>
            </tr>

            <!--          坍落度-->

            <tr trindex="0">
              <td width="100%" colspan="11" height="30">坍落度经时损失试验</td>
            </tr>
            <tr trindex="1">
              <td colspan="2" rowspan="2">样品编号</td>
              <td colspan="3">出机时混凝土拌合物坍落度(mm)</td>
              <td colspan="3">静置 min后混凝土拌合物坍落度(mm)</td>
              <td colspan="3" rowspan="2" style="width: 20%">坍落度经时损失(mm)</td>
            </tr>
            <tr trindex="1">
              <td colspan="2">单值</td>
              <td style="width: 10%">平均值</td>
              <td colspan="2">单值</td>
              <td style="width: 10%">平均值</td>
            </tr>
            <tr v-for="(e, index) of form.detailList" :key="e.index">
              <td colspan="2">{{ index + 1 }}</td>
              <td>
                <!-- {{ `${index + 1}_0` }} -->
                <el-input v-model="e.chujstld1" @blur="computeChujstldpj" @keydown.native="handleKeyDown($event, index + 1, 0)" :ref="`${index + 1}_0`" />
              </td>
              <td><el-input v-model="e.chujstld2" @blur="computeChujstldpj" @keydown.native="handleKeyDown($event, index + 1, 1)" :ref="`${index + 1}_1`" /></td>
              <td>{{ e.chujstldpj }}</td>
              <td><el-input v-model="e.jingzhtld1" @blur="computeJingzhtldpj" @keydown.native="handleKeyDown($event, index + 1, 2)" :ref="`${index + 1}_2`" /></td>
              <td><el-input v-model="e.jingzhtld2" @blur="computeJingzhtldpj" @keydown.native="handleKeyDown($event, index + 1, 3)" :ref="`${index + 1}_3`" /></td>
              <td>{{ e.jingzhtldpj }}</td>
              <td colspan="3">{{ e.tanldjsss }}</td>
            </tr>

            <!--          扩展度-->

            <tr trindex="0">
              <td width="100%" colspan="11" height="30">扩展度经时损失试验</td>
            </tr>
            <tr trindex="1">
              <td colspan="2" rowspan="2">样品编号</td>
              <td colspan="3">出机时混凝土拌合物扩展度(mm)</td>
              <td colspan="3">静置 min后混凝土拌合物扩展度(mm)</td>
              <td colspan="3" rowspan="2" style="width: 20%">扩展度经时损失(mm)</td>
            </tr>
            <tr trindex="1">
              <td colspan="2">单值</td>
              <td style="width: 10%">平均值</td>
              <td colspan="2">单值</td>
              <td style="width: 10%">平均值</td>
            </tr>
            <tr v-for="(e, index) of form.detailList" :key="e.index">
              <td colspan="2">{{ index + 1 }}</td>
              <td>
                <!-- {{ `${index + 5}_0` }}   -->
                <el-input v-model="e.chujskzd1" @blur="computechujskzdpj" @keydown.native="handleKeyDown($event, index + 5, 0)" :ref="`${index + 5}_0`" />
              </td>
              <td><el-input v-model="e.chujskzd2" @blur="computechujskzdpj" @keydown.native="handleKeyDown($event, index + 5, 1)" :ref="`${index + 5}_1`" /></td>
              <td>{{ e.chujskzdpj }}</td>
              <td><el-input v-model="e.jingzhkzd1" @blur="computejingzhkzdpj" @keydown.native="handleKeyDown($event, index + 5, 2)" :ref="`${index + 5}_2`" /></td>
              <td><el-input v-model="e.jingzhkzd2" @blur="computejingzhkzdpj" @keydown.native="handleKeyDown($event, index + 5, 3)" :ref="`${index + 5}_3`" /></td>
              <td>{{ e.jingzhkzdpj }}</td>
              <td colspan="3">{{ e.kuozdjsss }}</td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="66px" class="bottom-table">
          <tbody>
            <tr>
              <td>
                <el-input :rows="2" type="textarea" v-model="form.fujsm" @focus="handleFocus('fjsm')" />
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">记录：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">复核：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block ;margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType" />
    <bs-judge-base-edit-view ref="bsJudgeBaseEditViewRef" @submit="selectJudgeBaseEdit" :syType="syType" />
  </div>
</template>

<script>
import { getSnhntTldjkzdsyjlBsInfo } from "@/api/reportsnhnt/snhntTldjkzdsyjlBsInfo";
import { emptyConvert, handleFocus, handleKeyDown } from "@/views/reportForms/utils";
import decimal from "@/utils/big-decimal";

import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import { computeBiQualification } from "@/api/sycs/biQualification";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";
import BsJudgeBaseEditView from "@/views/sycs/bsJudgeBase/BsJudgeBaseEditView.vue";
export default {
  name: "bhw",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView,
    BsJudgeBaseEditView
  },
  data() {
    return {
      jilbh: "",
      form: {
        shiyrq: "2024年03月09日",
        gongcbwyt: "",
        jilbh: "",
        jiancdwmc: "山东路桥集团试验检测中心有限公司泰安高速公路施工总承包项目工地试验室",
        totalPage: "",
        page: "",
        jiancyj: "",
        zhuyyqsbmcjbh: "",
        gongcmc: "汾阳至石楼高速公路",
        yangpmc: "K39+820-K40+440原地面",
        yangpbh: "JTG/T 3610-2019",
        laiysj: "2022年03月09日",
        yangpsl: "3kg",
        yangpzt: "完好无损"
      },
      dateText: "2024年05月10日",
      readonly: false
    };
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    isPdf: {
      type: Boolean,
      default: () => false
    }
  },
  watch: {},
  created() {
    this.getInfo();
  },
  methods: {
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    // 获取详情
    getInfo() {
      // if (!this.excelId) {
      //   return;
      // }
      getSnhntTldjkzdsyjlBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },

    submitForm() {
      return this.form;
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      // this.$set(this.form, 'jiancyj', info.label);
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },

    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
      if (!info || !info.label) {
        return;
      }
      if (!this.form.pandyj) {
        this.form.pandyj = info.label;
      } else {
        if (info && info.label) {
          this.form.pandyj += "、" + info.label;
        }
      }
      // 添加指标 info.list
      let keys = [];
      info.list.forEach((item) => {
       if (this.form.baDetailVos[item.refQualId] && this.form.baDetailVos[item.refQualId].jiancjg) {
          this.form.baDetailVos[item.refQualId].symbolValue = item.symbolValue;
          this.form.baDetailVos[item.refQualId].num1 = item.num1;
          this.form.baDetailVos[item.refQualId].num2 = item.num2;
          keys.push(item.refQualId);
        }
      });
      this.computeDetectionResult(keys);
    },
    // 计算检测结果
    computeDetectionResult(keys) {
      if (!keys || keys.length <= 0) {
        return;
      }
      const data = keys.map((key) => {
        const info = {
          ...this.form.baDetailVos[key],
          jiancjg: this.form.baDetailVos[key].jiancjg == "-" ? "" : this.form.baDetailVos[key].jiancjg
        };
        return info;
      });
      computeBiQualification(data).then((res) => {
        const returnData = res.data;
        returnData.forEach((item) => {
          if (!item.symbolValue && !item.num1 && !item.num2) {
            item.jiszb = "-";
          }
          item.jiancjg = item.jiancjg ? item.jiancjg : "-";
          this.form.baDetailVos[item.qualId] = item;
        });
      });
    },
    // 获取检测结论
    getJcjl() {
      const form = JSON.parse(JSON.stringify(this.form));
      queryJcjl(emptyConvert(form)).then((res) => {
        const info = res.data;
        this.form.jiancjl = info.jiancjl;
      });
    },
    // 编辑单个技术指标后赋值
    selectJudgeBaseEdit(info) {
      if (info.qualId) {
        this.form.baDetailVos[info.qualId] = info;
      }
      this.computeDetectionResult([info.qualId]);
    },

    //出机时混凝土拌合物坍落度
    computeChujstldpj() {
      if (this.form.detailList) {
        this.form.detailList.forEach((e) => {
          if (e.chujstld1 && e.chujstld2) {
            e.chujstldpj = this.xiuYue5(decimal.divide(decimal.add(e.chujstld1, e.chujstld2, 9), 2, 0));
          } else {
            e.chujstldpj = null;
          }
          if (e.chujstldpj && e.jingzhtldpj) {
            e.tanldjsss = decimal.subtract(e.chujstldpj, e.jingzhtldpj, 0);
          } else {
            e.tanldjsss = null;
          }
        });
      }
    },
    //静置 min后混凝土拌合物坍落度
    computeJingzhtldpj() {
      if (this.form.detailList) {
        this.form.detailList.forEach((e) => {
          if (e.jingzhtld1 && e.jingzhtld2) {
            e.jingzhtldpj = this.xiuYue5(decimal.divide(decimal.add(e.jingzhtld1, e.jingzhtld2, 9), 2, 0));
          } else {
            e.jingzhtldpj = null;
          }
          if (e.chujstldpj && e.jingzhtldpj) {
            e.tanldjsss = decimal.subtract(e.chujstldpj, e.jingzhtldpj, 0);
          } else {
            e.tanldjsss = null;
          }
        });
      }
    },
    //出机时混凝土拌合物扩展度
    computechujskzdpj() {
      if (this.form.detailList) {
        this.form.detailList.forEach((e) => {
          if (e.chujskzd1 && e.chujskzd2) {
            e.chujskzdpj = this.xiuYue5(decimal.divide(decimal.add(e.chujskzd1, e.chujskzd2, 9), 2, 0));
          } else {
            e.chujskzdpj = null;
          }
          if (e.chujskzdpj && e.jingzhkzdpj) {
            e.kuozdjsss = decimal.subtract(e.chujskzdpj, e.jingzhkzdpj, 0);
          } else {
            e.kuozdjsss = null;
          }
        });
      }
    },
    //静置   min后混凝土拌合物扩展度
    computejingzhkzdpj() {
      if (this.form.detailList) {
        this.form.detailList.forEach((e) => {
          if (e.jingzhkzd1 && e.jingzhkzd2) {
            e.jingzhkzdpj = this.xiuYue5(decimal.divide(decimal.add(e.jingzhkzd1, e.jingzhkzd2, 9), 2, 0));
          } else {
            e.jingzhkzdpj = null;
          }
          if (e.chujskzdpj && e.jingzhkzdpj) {
            e.kuozdjsss = decimal.subtract(e.chujskzdpj, e.jingzhkzdpj, 0);
          } else {
            e.kuozdjsss = null;
          }
        });
      }
    },
    //将数字保留至5；即5,10；
    xiuYue5(num) {
      let yushu = num % 5;
      if (yushu == 0) {
        return num;
      }
      let beishu = (num / 5) >> 0;
      if (yushu > 2.5) {
        return 5 * (beishu + 1);
      } else {
        return 5 * beishu;
      }
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [0, 3, 3, 3, 3, 3, 3, 3, 3];
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]?.length) {
        this.$refs[ref][0].focus();
      } else if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped lang="scss">
</style>
